package org.example;

/**
 * <b>LockStudy.java</b></br>
 *
 * <pre>
 *     锁研究
 * </pre>
 *
 * @author zhoulihao xiaogezhou929@163.com
 * @date 2021年06月11日 10:34:08
 * @since JDK 1.8
 */
public class LockStudy {
    private int count;

    public static void main(String[] args) {
        LockStudy ls = new LockStudy();

        ls.getAndInc(10);

        System.out.println(ls.count);

    }

    public synchronized int getAndInc(int c) {
        int count = this.count;
        //可重入锁，getAndInc()中调用了inc
        inc(c);

        return count;

    }

    public synchronized void inc(int c) {
        count = count + c;

    }

}
